<template>
	<div>
		<Header></Header>
		<view class="form-view">
			<form @submit="formSubmit" class="form">
				<label for="" class="form-label form-label-title">套餐选择</label>
				<picker mode="selector" :range="pickerRange" @change="bindPickerChange" :value="pickerIndex" range-key="name" class="form-picker"
				 id="picker" name='option'>
					<view class="uni-input">{{pickerRange[pickerIndex].name}}</view>
				</picker>
				<label for="" class="form-label form-label-title">信息填写</label>
				<view class="form-label-input">
					<label for="" class="form-label">客户姓名</label>
					<input type="text" v-model="userInfo.name" placeholder="请输入信息" class="form-input" placeholder-class='input-placeholder'
					 name='name' />
				</view>
				<view class="form-label-radio-group">
					<label for="" class="form-label">证件类型</label>
					<radio-group class="radio-group" @change='radioGroupChange' name='type'>
						<view class="radio-view">
							<radio value="1" :checked='userInfo.type==1' /><text>身份证</text>
						</view>
						<view class="radio-view">
							<radio value="2" :checked='userInfo.type==2' /><text>营业执照</text>
						</view>
					</radio-group>
				</view>
				<view class="form-label-input">
					<label for="" class="form-label">证件号码</label>
					<input type="text" v-model="userInfo.idno" placeholder="请输入证件号码" class="form-input" placeholder-class='input-placeholder'
					 name='idno' />
				</view>
				<view class="form-label-input">
					<label for="" class="form-label">经办人姓名</label>
					<input type="text" v-model="userInfo.realName" placeholder="请输入姓名" class="form-input" name='realName' />
				</view>
				<view class="form-label-input">
					<label for="" class="form-label">经办人身份证号码</label>
					<input type="text" v-model="userInfo.realIdNo" placeholder="请输入证件号码" class="form-input" placeholder-class='input-placeholder'
					 name='realIdNo' />
				</view>
				<view class="form-label-input">
					<label for="" class="form-label">联系电话</label>
					<input type="number" v-model="userInfo.phone" placeholder="请输入联系电话" class="form-input" placeholder-class='input-placeholder'
					 name='phone' />
				</view>
				<view class="form-label-input form-label-textarea">
					<label for="" class="form-label">备注</label>
					<textarea v-model="userInfo.note" placeholder="如希望什么时间上门安装（明天下午3到4点）" class="form-textarea" placeholder-class="input-placeholder"
					 name="note" />
					</view>
				<view>
					<checkbox-group @change='bindAgreeChange' class="checkbox-group" name='agree'>
						<label for="checkboxId" class="">
							<checkbox value="1" class="checkbox" color="#26a2ff" id='checkboxId' :checked="userInfo.agree == true" />
							<text>我已阅读并同意 <b @click="show_open1()">《中国电信深圳分公司服务协议》 </b>
								和
								<b @click="show_open2()">《申请使用通信服务涉电信网络新型违法犯罪的法律责任及防范提示告知书（暂行）》</b></text>
						</label>
					</checkbox-group>
				</view>
				<button type="primary" form-type="submit" class="form-button" :class="userInfo.agree?'':'form-button-disable'"
				 :disabled="!userInfo.agree">提交</button>
			</form>
		</view>

	</div>
</template>


<script>
	import Header from './../header'
	import agreeObj from './agree.js'

	export default {
		data() {
			return {
				pickerIndex: 0,
				slots: [{
					flex: 1,
					values: [

					],
					className: 'slot1',
					textAlign: 'center',
					defaultIndex: 0
				}],
				pickerRange: [],
				czcOptions: [{
						'name': '城中村融合礼包200M：1668元包年(包一年光纤+一年手机套餐费)',
						'id': 1
					},
					{
						'name': '城中村融合套餐200M：预存300元套餐费月供114元/月',
						'id': 2
					},
					{
						'name': '城中村单宽带100M：150元包月',
						'id': 3
					},
					{
						'name': '城中村单宽带100M：1650元包年',
						'id': 4
					}
				],
				xqOptions: [{
						'name': '小区融合套餐300M：预存600元套餐费月供189元/月',
						'id': 5
					},
					{
						'name': '小区融合套餐500M：预存600元套餐费月供219元/月',
						'id': 6
					},
					{
						'name': '单宽带300M：200元包月',
						'id': 7
					},
					{
						'name': '单宽带300M：2200元包年',
						'id': 8
					}
				],
				zxOptions: [{
						'name': '专线融合套餐：299元/月(包500M光纤+80G流量+1000分钟时长)',
						'id': 9
					},
					{
						'name': '专线融合套餐：3588元/年(包500M光纤一年+一年手机套餐费)',
						'id': 10
					},
					{
						'name': '专线融合套餐：699元/月(包1000M光纤+100G流量+1500分钟时长)',
						'id': 11
					},
					{
						'name': '商务专线单宽带500M：599元/月',
						'id': 12
					},
					{
						'name': '商务专线单宽带1000M：999元/月',
						'id': 13
					},
				],
				userInfo: {
					option: '',
					name: '',
					type: 1,
					idno: '',
					realName: '',
					realIdNo: '',
					phone: '',
					note: '',
					agree: false
				},
			}
		},
		components: {
			Header
		},
		created() {
			this.pickerRange = [
				...this.czcOptions,
				...this.xqOptions,
				...this.zxOptions
			]
		},
		mounted() {

		},
		onShow() {
			let val = getApp().globalData.userInfo.option
			this.userInfo.option = val
			for (let k in this.pickerRange) {
				if (this.pickerRange[k].id == val) {
					this.pickerIndex = k
					break
				}
			}
			// console.log(this.userInfo)
		},
		methods: {
			onValuesChange(picker, values) {
				console.log(values)
				if (values[0] > values[1]) {
					picker.setSlotValue(1, values[0]);
				}
			},
			bindPickerChange(e) {
				// console.log(e)
				this.pickerIndex = e.detail.value
			},
			radioGroupChange(e) {
				console.log(e.detail.value)
			},
			bindAgreeChange(e) {
				console.log(e.detail.value)
				this.userInfo.agree = e.detail.value == '1'
			},
			show_open1() {
				// console.log(1)
				uni.showModal({
					title: agreeObj.service.title,
					content: agreeObj.service.content,
					showCancel: false,
					confirmColor: '#26a2ff'
				})
				// this.userInfo.agree = false
			},
			show_open2() {
				// console.log(2)
				uni.showModal({
					title: agreeObj.notice.title,
					content: agreeObj.notice.content,
					showCancel: false,
					confirmColor: '#26a2ff'
				})
				// this.userInfo.agree = false
			},
			formSubmit(e) {
				let userInfo = e.detail.value
				userInfo.option = this.pickerRange[userInfo.option].id
				userInfo.agree = userInfo.agree.length > 0
				console.log(userInfo)
			}
		},

	}
</script>

<style scoped lang="scss">
	.form-view {
		padding: 0 10rpx;
	}

	.form {
		.form-label {
			height: 88rpx;
			line-height: 88rpx;
			min-width: 180rpx;
			font-size: 30rpx;
			// font-weight: bold;
			color: #000;
		}

		.form-label-title {
			height: 68rpx;
			line-height: 68rpx;
			font-size: 36rpx;
			font-weight: bold;
		}

		.form-picker {
			min-height: 48*2rpx;
			line-height: 40rpx;
			border-bottom: 1rpx solid #ccc;

			.uni-input {
				font-size: 28rpx;
			}
		}

		.form-label-radio-group {
			display: flex;
			align-items: flex-start;
			border-bottom: 1rpx solid #ccc;

			.form-label {
				// min-width: 200rpx;
			}

			.radio-group {
				font-size: 32rpx;

				.radio-view {
					margin: 20rpx 35rpx;
				}
			}
		}

		.form-label-input {
			height: 44*2rpx;
			line-height: 44*2rpx;
			display: flex;
			align-items: center;
			border-bottom: 1rpx solid #ccc;

			.form-label {}

			.input-placeholder {
				font-size: 28rpx;
				color: #999;
			}

			.form-input {
				margin-left: 30rpx;
				font-size: 30rpx;
				color: #333;
			}

			.form-textarea {
				height: 80rpx;
				line-height: 40rpx;
				margin-left: 30rpx;
				padding: 20rpx 0;
				font-size: 30rpx;
				color: #333;
			}
		}

		.form-label-textarea {
			height: auto;
			align-items: flex-start;
		}

		.form-button {
			width: 300*2rpx;
			height: 80rpx;
			line-height: 80rpx;
			color: #FFFFFF;
			font-size: 32rpx;
			border: none;
			margin-bottom: 60rpx;
			margin-top: 30rpx;
			background-color: #26a2ff;

			&::after {
				border: none;
			}
		}

		.form-button-disable {
			opacity: 0.5;
			color: #eee;
		}
	}

	// 修改checkbox的默认样式
	/* #ifdef H5 */
	checkbox /deep/ .uni-checkbox-input {
		border-radius: 50%;
	}

	checkbox /deep/ .uni-checkbox-input.uni-checkbox-input-checked {
		border: 1rpx solid #26a2ff;
		background: #26a2ff;
		color: #fff !important;
	}

	checkbox /deep/ .uni-checkbox-input.uni-checkbox-input-checked::before {
		font-size: 36rpx;
	}

	/* #endif */
	/* #ifdef APP-PLUS || MP-WEIXIN */
	checkbox .wx-checkbox-input {
		border-radius: 50%;
	}

	checkbox .wx-checkbox-input.wx-checkbox-input-checked {
		border: 1rpx solid #26a2ff;
		background: #26a2ff;
		color: #fff !important;
	}

	checkbox .wx-checkbox-input.wx-checkbox-input-checked::before {
		font-size: 36rpx;
	}

	/* #endif */

	.checkbox-group {
		padding: 20rpx 0;
		line-height: 40rpx;
		font-size: 28rpx;

		.checkbox {}

		b {
			color: #ffbc00;
			font-weight: bolder;
		}
	}
</style>
